﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microsoft.Practices.ServiceLocation;
using AzureGames.Web.Models;

using Handlers = AzureGames.Domain.Handlers;

namespace AzureGames.Web.Controllers
{
    public class AIController : AuthorizedController
    {
        public AIController(IServiceLocator serviceLocator) : base(serviceLocator) { }

        public ActionResult Extend(int id)
        {
            var games = Using<Handlers.GetGameDefinitionList>().Execute();

            var model = new DashboardViewModel
            {
                GameListViewModel = new GameDefinitionListViewModel(games, id)
            }.GameListViewModel.SelectedGame;

            return View(model);
        }

        [HttpPost]
        public ActionResult Extend(int id, HttpPostedFileBase scriptFile)
        {
            Using<Handlers.UpdateGame>().Execute(id, scriptFile);
            //CCTODO implement this
            return null;
        }

        [HttpPost]
        //[Authorize]
        public JsonResult JsonConfigure(int id)
        {
            //var game = Using<Handlers.GetGameDefinition>()
            //    .Execute(gameDefinitionID: id);

            //var vm = ToJsonGameViewModel(game);

            //return Json(vm);
            return null;
        }

        private JsonGameViewModel ToJsonGameViewModel(Domain.Models.GameDefinition game)
        {
            return new JsonGameViewModel
            {
                GameId = game.ID,
                Name = game.Name
            };
        }
    }
}
